package cn.gok;

import java.util.*;
import java.util.stream.Stream;

class Book implements Comparable<Book>{
    private int bid;
    private String bname;
    private float price;

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getBname() {
        return bname;
    }

    public void setBname(String bname) {
        this.bname = bname;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public Book(int bid, String bname, float price) {
        this.bid = bid;
        this.bname = bname;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bid=" + bid +
                ", bname='" + bname + '\'' +
                ", price=" + price +
                '}';
    }

    @Override
    public int compareTo(Book o) {
        if (this.getPrice()<o.getPrice()){
            return 1;
        }else if(this.getPrice()==o.getPrice()&&this.getBname().equals(o.getBname())){
            return 0;
        }
        return -1;
    }

}
class BookCompartor implements Comparator<Book> {

    @Override
    public int compare(Book o1, Book o2) {
        if (o1.getPrice()<o2.getPrice()){
            return 1;
        }else if(o1.getPrice()==o2.getPrice()&&o1.getBname().equals(o2.getBname())){
            return 0;
        }
        return -1;
    }

}
public class homework6 {
    public static void main(String[] args) {
        //作业1();
        作业2();
    }

    private static void 作业2() {
        List<Book> list = Arrays.asList(new Book(1,"西游记",100),new Book(2,"水浒传",210),new Book(3,"三国演义",150),new Book(4,"红楼梦",120),new Book(5,"活着",200));
        Stream<Book> s1 = list.stream();//普通流
        s1.filter((book)->{return book.getPrice()<150;}).forEach(System.out::println);
    }

    private static void 作业1() {
        TreeMap<Book,String> map=new TreeMap<>();
        map.put(new Book(1,"西游记",100),"老白1");
        map.put(new Book(2,"水浒传",210),"老白2");
        map.put(new Book(3,"三国演义",150),"老白3");
        map.put(new Book(4,"红楼梦",120),"老白4");
        map.put(new Book(5,"活着",200),"老白5");
        System.out.println(map);
        System.out.println("--------------------");
        //按Keyset遍历
        for(Book key:map.keySet()){
            String value=map.get(key);
            System.out.println(key+"-----"+value);
        }
        System.out.println("-------------------------");
        //按entrySet遍历
        for (Map.Entry<Book,String> e:map.entrySet()){
            Book key =e.getKey();
            String vaulue =e.getValue();
            System.out.println(key+"----------"+vaulue);
        }
        System.out.println("--------------------------");

    }
}
